﻿using simulate_da_click.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace simulate_da_click.BusinessLogic {
    internal class SimulationRuntime {

        private Timer _timer;
        private readonly SimulationConfiguration _simulationConfiguration;

        public SimulationRuntime(SimulationConfiguration simulationConfiguration) {
            _timer = new Timer();
            _timer.Elapsed += _timer_Elapsed;
            _simulationConfiguration = simulationConfiguration;
        }

        void _timer_Elapsed(object sender, ElapsedEventArgs e) {
            Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
            //Mouse.SimulateClick(_simulationConfiguration.TargetMouseLocation);
        }
        
        internal void StartSimulation() {
            var location = _simulationConfiguration.TargetMouseLocation;
            if (_simulationConfiguration.IntervalTime == IntervalTimeEnum.Second)
                _timer.Interval = 1;
            else if(_simulationConfiguration.IntervalTime == IntervalTimeEnum.Minute)
                _timer.Interval = (60000* _simulationConfiguration.Interval) /  _simulationConfiguration.Interval;

            _timer.Start();
        }

        internal void StopSimulation() {
            _timer.Stop();
        }
    }
}
